#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int t;
int n,m,l,V;
int ans[N];
int d[N],a[N],v[N],lt[N],cs[N],nb[N];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n>>m>>l>>V;
        for(int i=1; i<=n; i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1; i<=m; i++){
            cin>>cs[i];
        }
        sort(cs+1,cs+m+1);
        for(int i=1; i<=n; i++){//csc
            if(a[i]<0&& v[i]>V){
                for(int j=1; j<=m; j++){//csd
                    if(d[i]>cs[j]) continue;
                    int s=cs[j]-d[i];
                    double vv=sqrt(v[i]*v[i]*1.0+2.0*a[i]*s);
                    int cc=ceil(vv);
                    if(cc>V){
                        lt[j]++;
                        ans[i]=j;
                        break;
                    }
                }
            }
        }

        for(int i=1; i<=m; i++){//icsd
            for(int j=1; j<=n; j++){//jcsc
                if(ans[j]==0){
                    if(d[j]>cs[i]) continue;
                    else{
                    int s=cs[i]-d[j];
                    double vv=sqrt(v[j]*v[j]*1.0+2.0*a[j]*s);
                    int cc=ceil(vv);
                      if(cc>V){
                        lt[i]++;
                        ans[j]=i;
                        break;
                      }
                    }
                }

            }
        }
        int ans1=0,ans2=0;
        for(int i=1; i<=n; i++){
 //           cout<<ans[i]<<" ";
            ans1+=(ans[i]!=0);
        }
 //       cout<<endl;
        for(int i=1; i<=m; i++){
 //           cout<<lt[i]<<" ";
            if(lt[i]==0) ans2++;
        }
//        cout<<endl;
        cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}
